<?php
/**
Spl 四种常用的数据结构
*/

//栈:先进后出
$stack = new SplStack();
$stack->push('data1<br>'); //入栈
$stack->push('data2<br>');

echo $stack->pop();//出栈
echo $stack->pop();
echo '<hr>';


//队列：先进先出
$queue = new SplQueue();
$queue->enqueue('data3<br>');
$queue->enqueue('data4<br>');

echo $queue->dequeue();
echo $queue->dequeue();
echo '<hr>';

//The SplMinHeap class provides the main functionalities of a heap, keeping the minimum on the top.
$heap = new SplMinHeap();
$heap->insert('data5<br>');
$heap->insert('data6<br>');

echo $heap->extract();
echo $heap->extract();
echo '<hr>';


//固定长度的数组
$arr = new SplFixedArray(10);
$arr[0] = 'xiao';
$arr[7] = 'jing';
var_dump($arr);